package index6;


import index5.Numero4;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class radionButt
  extends JFrame
{
  private JRadioButton gaucheRadioButton = new JRadioButton();
  private JRadioButton centreRadioButton = new JRadioButton();
  private JRadioButton DroiteRadioButton = new JRadioButton();
  private JTextField jTextField1 = new JTextField();

  public radionButt()
  {
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  private void jbInit()
    throws Exception
  {
    this.getContentPane().setLayout( null );
    this.setSize( new Dimension(400, 300) );
    gaucheRadioButton.setText("Gauche");
    gaucheRadioButton.setBounds(new Rectangle(35, 155, 86, 18));
    centreRadioButton.setText("Centre");
    centreRadioButton.setBounds(new Rectangle(140, 155, 86, 18));
    DroiteRadioButton.setText("Droite");
    DroiteRadioButton.setBounds(new Rectangle(245, 155, 86, 18));
    jTextField1.setBounds(new Rectangle(40, 45, 290, 75));
    this.getContentPane().add(DroiteRadioButton, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(centreRadioButton, null);
    this.getContentPane().add(gaucheRadioButton, null);
    ButtonGroup groupeSex = new ButtonGroup();
    
    groupeSex.add(gaucheRadioButton);
    groupeSex.add(centreRadioButton);
    groupeSex.add(DroiteRadioButton);
    
    EcouteurDeFenetre ec = new EcouteurDeFenetre();
    gaucheRadioButton.addItemListener(ec);
    centreRadioButton.addItemListener(ec);
    DroiteRadioButton.addItemListener(ec);
    
  }
  private class EcouteurDeFenetre implements ItemListener
  {

    public void itemStateChanged(ItemEvent e)
    {
      if (e.getSource().equals(gaucheRadioButton))
      jTextField1.setHorizontalAlignment(jTextField1.LEFT);
      else if (e.getSource().equals(centreRadioButton))
      jTextField1.setHorizontalAlignment(jTextField1.CENTER);
      else
      jTextField1.setHorizontalAlignment(jTextField1.RIGHT);
    }
  }
}
